#include "tee_internal_api.h"
#include "tee_api_defines.h"
#include "trace.h"
#include "tee_api_defines_extensions.h"

/*
 * Ciphering context: each opened session relates to a cipehring operation.
 * - configure the AES flavour from a command.
 * - load key from a command (here the key is provided by the REE)
 * - reset init vector (here IV is provided by the REE)
 * - cipher a buffer frame (here input and output buffers are non-secure)
 */
struct aes_cipher {
	uint32_t algo;			/* AES flavour */
	uint32_t mode;			/* Encode or decode */
	uint32_t key_size;		/* AES key size in byte */
	TEE_OperationHandle op_handle;	/* AES ciphering operation */
	TEE_ObjectHandle key_handle;	/* transient object to load the key */
};


#define TA_AES_MODE_ENCODE		1
#define TA_AES_MODE_DECODE		0

#define TA_AES_ALGO_ECB			0
#define TA_AES_ALGO_CBC			1
#define TA_AES_ALGO_CTR			2

#define TA_AES_SIZE_128BIT		(128 / 8)
#define TA_AES_SIZE_256BIT		(256 / 8)

#define AES128_KEY_BIT_SIZE		128
#define AES128_KEY_BYTE_SIZE		(AES128_KEY_BIT_SIZE / 8)
#define AES256_KEY_BIT_SIZE		256
#define AES256_KEY_BYTE_SIZE		(AES256_KEY_BIT_SIZE / 8)


#define AES_TEST_BUFFER_SIZE	4096
#define AES_TEST_KEY_SIZE	16
#define AES_BLOCK_SIZE		16

extern TEE_Result ta2tee_algo_id(uint32_t param, uint32_t *algo);
extern TEE_Result ta2tee_key_size(uint32_t param, uint32_t *key_size);
extern TEE_Result ta2tee_mode_id(uint32_t param, uint32_t *mode);
extern TEE_Result alloc_resources(void *session, uint32_t param_types, TEE_Param params[4]);
extern TEE_Result set_aes_key(void *session, uint32_t param_types,TEE_Param params[4]);
extern TEE_Result reset_aes_iv(void *session, uint32_t param_types,TEE_Param params[4]);
extern TEE_Result cipher_buffer(void *session, uint32_t param_types,TEE_Param params[4]);